package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.common.CapitalGoodsResult;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.CapitalGoods;
import com.yh.homestay.service.CapitalGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName CapitalGoodsController
 * @Description 物资Controller
 * @Date 2020/1/13 15:07
 */
@RestController
@RequestMapping(value = "/materiel")
@Api(description = "物资管理")
public class CapitalGoodsController {
    @Autowired
    private CapitalGoodsService capitalGoodsService;

    /**
     * @param page
     * @param limit
     * @param start
     * @param end
     * @param goodsName
     * @Date: 2020/1/13 15:18
     * @Description: 物资展示
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @SystemLog(methods = "物资展示", module = "物资管理")
    @ApiOperation(value = "获取所有物资列表", notes = "获取所有物资信息或者模糊查询")
    public HomeStayResult findAllMatriel(Integer page, Integer limit, String start, String end, String goodsName) {

        return capitalGoodsService.findAllCapitalGoods(page, limit, start, end, goodsName);
    }

    /**
     * @param good
     * @Date: 2020/1/13 15:19
     * @Description: 添加物资
     * @return: com.yh.homestay.common.CapitalGoodsResult
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @SystemLog(methods = "添加物资", module = "物资管理")
    @ApiOperation(value = "添加物资", notes = "添加物资信息")
    public CapitalGoodsResult addMateriel(CapitalGoods good) {
        //补全对象属性
        good.setGoodsType(1);
        good.setGoodsArea("仓库");
        return capitalGoodsService.addCapitalGood(good);
    }

    /**
     * @param goodsNumber
     * @Date: 2020/1/13 15:19
     * @Description: 删除物资
     * @return: com.yh.homestay.common.CapitalGoodsResult
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @SystemLog(methods = "删除物资", module = "物资管理")
    @ApiOperation(value = "删除物资", notes = "根据id删除物资")
    public CapitalGoodsResult delSingle(String goodsNumber) {
        return capitalGoodsService.delSingleCapitalGood(goodsNumber);
    }

    /**
     * @param nums
     * @Date: 2020/1/13 15:19
     * @Description: 批量删除物资
     * @return: com.yh.homestay.common.CapitalGoodsResult
     */
    @RequestMapping(value = "/deleteBatch",method = RequestMethod.POST)
    @SystemLog(methods = "删除多个物资", module = "物资管理")
    @ApiOperation(value = "批量删除物资", notes = "根据ids批量删除物资")
    public CapitalGoodsResult del(String nums) {
        return capitalGoodsService.delCapitalGood(nums);

    }

    /**
     * @param num
     * @Date: 2020/1/13 15:19
     * @Description: 回显物资信息
     * @return: com.yh.homestay.common.CapitalGoodsResult
     */
    @RequestMapping(value = "/toMaterieledit/{num}",method = RequestMethod.POST)
    @SystemLog(methods = "查看物资详情", module = "物资管理")
    @ApiOperation(value = "回显物资信息", notes = "回显物资详情信息")
    public CapitalGoodsResult seleteCapitalSingle(@PathVariable String num) {
        return capitalGoodsService.seleteCapitalSingle(num);

    }

    /**
     * @param good
     * @Date: 2020/1/13 15:19
     * @Description: 修改物资信息
     * @return: com.yh.homestay.common.CapitalGoodsResult
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @SystemLog(methods = "修改物资信息", module = "物资管理")
    @ApiOperation(value = "修改物资信息", notes = "根据id修改物资信息")
    public CapitalGoodsResult updateMateriel(CapitalGoods good) {
        return capitalGoodsService.updataMaterielSingle(good);
    }


}
